package com.spikything.ui {
	
	import com.spikything.ui.LabelledButton;
	import flash.display.DisplayObject;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.events.MouseEvent;
	import com.spikything.gfx.Scale9Bitmap;
	import com.spikything.gfx.TextLabel;
	import com.irisnation.ing.formula1.Assets;

	public class IconButton extends LabelledButton {
		
		public var 		defaultIcon 	:DisplayObject;
		protected const ICON_PADDING 	:Number 	= 0;
		protected var 	soundOffIcon 	:Class 		= Assets.SOUND_OFF_ICON;
		protected var 	soundOnIcon 	:Class 		= Assets.SOUND_ON_ICON;
		protected var 	playIcon 		:Class 		= Assets.PLAY_ICON;
		protected var 	pauseIcon 		:Class 		= Assets.PAUSE_ICON;
		protected var 	fullscreenIcon 	:Class 		= Assets.FULLSCREEN_ICON;
		
		public function IconButton (icon:String = "", x:Number = 0, y:Number = 0, label:String = "") {
			super(label, x, y);
			setup(icon, label);
			_background.visible = false;
		}
		
		public function addIcon (icon:String, x:Number=0):Bitmap {
			var myicon:Bitmap = addChild(new this[icon]() as Bitmap) as Bitmap;
			myicon.x = x;
			return myicon;
		}
		
		override protected function getRounding ():Number {
			return 0;
		}
		
		protected function setup (icon:String, label:String):void {
			defaultIcon = addChild(new this[icon]() as Bitmap);
			defaultIcon.x = defaultIcon.y = ICON_PADDING;
			
			if (label.length) {
				_background.width += defaultIcon.width + ICON_PADDING;
				_labelField.x += defaultIcon.width;
				defaultIcon.x += 2;
			} else {
				_background.width = defaultIcon.width + (ICON_PADDING*2);
				_background.height = defaultIcon.height + (ICON_PADDING*2);
			}
		}
		
	}
	
}